package com.ssy.lingxi.product.repository.platform;

import com.ssy.lingxi.product.entity.platform.Category;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 品类持久化层
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/22
 */
public interface CategoryRepository extends JpaRepository<Category,Long>, JpaSpecificationExecutor<Category> {
    Page<Category> findByNameContaining(String name, Pageable page);

    @Query("select max(c.level) from Category c")
    Integer findMaxLevel();

    List<Category> findByLevelAndNameAndParentIdAndIdNot(Integer level, String name, Long parentId, Long id);

    List<Category> findByLevelAndName(Integer level, String name);

    List<Category> findByParentId(Long parentId);

    List<Category> findByFullIdStartingWith(String categoryIdKey);

    List<Category> findByFullIdLike(String categoryIdKey);

    List<Category>  findByIdIn(List<Long> categoryIdList);

    List<Category> findByAttributeListId(Long id);
}
